package cfca.paperless.client.servlet._2_extend._2_08_BindPreCert;

import java.util.Date;

import cfca.paperless.client.bean.CertInfo;
import cfca.paperless.client.servlet.PaperlessClient;
import cfca.paperless.client.servlet.PaperlessConfig;
import cfca.paperless.client.util.GUID;
import cfca.paperless.client.util.StrategyUtil;
import cfca.paperless.client.util.StringUtil;

public class BindPreCertTest01 {

    /**
     * 预植场景证书绑定
     * 
     * @param args
     * @throws IOException
     * @throws
     */
    public static void main(String[] args) throws Exception {
        try {
            long timeStart = System.currentTimeMillis();// 开始时间

            // 初始化客户端对象
            PaperlessClient clientBean = new PaperlessClient(PaperlessConfig.proxyUrl, 10000, 60000);// 无纸化辅助接口的访问URL

            // 策略文件
            String userInfoXml = StrategyUtil.createUserInfoXml("张三", "Z", "00000000", "22", "dkfjdkjfkdjfkdjfkjdk");
            String certId = GUID.generateId();
            String certSn = "aadfdfdfdfdf";
            String certDn = "11223365488";
            String keyAlg = "RSA";
            int keyLength = 2048;
            String certHash = "aaa44df4dfdfdfdf";
            String certKeyIdentifier = "dddddddddddddfffffff";
            CertInfo certInfo = new CertInfo(certId, certSn, certDn, keyAlg, keyLength, certHash, certKeyIdentifier);
            String certInfoXml = StrategyUtil.createCertInfoXml(certInfo);
            // 操作员编码或者机构号
            String operatorCode = PaperlessConfig.operatorCode;
            // 渠道编码，可以为空
            String channelCode = PaperlessConfig.channelCode;
 
            String returnMessage = clientBean.bindPreCert(userInfoXml, certInfoXml, operatorCode, channelCode);

            String code = StringUtil.getNodeText(returnMessage, "Code");
            if ("200".equals(code)) {
                System.out.println("bindPreCert ok");
                System.out.println(returnMessage);
            } else {
                System.out.println(returnMessage);
            }
            long timeEnd = System.currentTimeMillis();// 结束时间
            System.out.println("time:" + (timeEnd - timeStart));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }



}
